/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JInternalFrameAceptarUsuarioTorneo.java
 *
 * Created on 07/11/2009, 09:51:08
 */

package com.grandt.view.ventanas.internas;

import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.DefaultListModel;

import com.grandt.controller.ventanas.internas.ControllerAceptarUsuarioTorneo;
import com.grandt.model.beans.equipo.Equipo;
import com.grandt.model.manager.ModelGranDT;
import com.grandt.view.utils.Messages;

/**
 *
 * @author jhonny
 */
public class JInternalFrameAceptarUsuarioTorneo extends javax.swing.JInternalFrame {

    /**
	 * 
	 */
	private static final long serialVersionUID = -4605471041372554130L;
	private ControllerAceptarUsuarioTorneo controller;
	
	/** Creates new form JInternalFrameAceptarUsuarioTorneo */
    public JInternalFrameAceptarUsuarioTorneo(ModelGranDT model) {
        initComponents();
        controller = new ControllerAceptarUsuarioTorneo(model,this);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelMain = new javax.swing.JPanel();
        buttonCancelar = new javax.swing.JButton();
        label = new javax.swing.JLabel();
        buttonOk = new javax.swing.JButton();
        scrollPane = new javax.swing.JScrollPane();
        listPostulantes = new javax.swing.JList();

        listPostulantes.setModel(new DefaultListModel());
        setClosable(true);
        ResourceBundle resourceMap = ResourceBundle.getBundle("com/grandt/view/ventanas/internas/resources/JInternalFrameAceptarUsuarioTorneo",Locale.getDefault());    
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        panelMain.setName("panelMain"); // NOI18N

        buttonCancelar.setText(resourceMap.getString("buttonCancelar.text")); // NOI18N
        buttonCancelar.setName("buttonCancelar"); // NOI18N
        buttonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCancelarActionPerformed(evt);
            }
        });

        label.setText(resourceMap.getString("label.text")); // NOI18N
        label.setName("label"); // NOI18N

        buttonOk.setText(resourceMap.getString("buttonOk.text")); // NOI18N
        buttonOk.setName("buttonOk"); // NOI18N
        buttonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonOkActionPerformed(evt);
            }
        });

        scrollPane.setName("scrollPane"); // NOI18N

        listPostulantes.setName("listPostulantes"); // NOI18N
        scrollPane.setViewportView(listPostulantes);

        javax.swing.GroupLayout panelMainLayout = new javax.swing.GroupLayout(panelMain);
        panelMain.setLayout(panelMainLayout);
        panelMainLayout.setHorizontalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMainLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, panelMainLayout.createSequentialGroup()
                        .addGroup(panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(panelMainLayout.createSequentialGroup()
                                .addComponent(label)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 73, Short.MAX_VALUE))
                            .addGroup(panelMainLayout.createSequentialGroup()
                                .addComponent(buttonOk)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(buttonCancelar)))
                .addContainerGap())
        );

        panelMainLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonCancelar, buttonOk});

        panelMainLayout.setVerticalGroup(
            panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelMainLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(label)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelMainLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(buttonCancelar)
                    .addComponent(buttonOk))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelMain, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buttonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonOkActionPerformed
    	try {
			controller.ok();
    	} catch (Exception e) {		
			Messages.showMessage(e, this);
		}
    }//GEN-LAST:event_buttonOkActionPerformed

    private void buttonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCancelarActionPerformed
    	controller.cancel();
    }//GEN-LAST:event_buttonCancelarActionPerformed


    @Override
    public void setVisible(boolean arg0) {
    	if(arg0){
    		controller.initComponentView();
    	}
    	super.setVisible(arg0);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonCancelar;
    private javax.swing.JButton buttonOk;
    private javax.swing.JLabel label;
    private javax.swing.JList listPostulantes;
    private javax.swing.JPanel panelMain;
    private javax.swing.JScrollPane scrollPane;

	public void initListPostulantes(List<Equipo> postulantesTorneoAmigo) {
		((DefaultListModel)listPostulantes.getModel()).removeAllElements();
		for (Equipo equipo : postulantesTorneoAmigo) {
			((DefaultListModel)listPostulantes.getModel()).addElement(equipo);
		}
		
	}

	public List<Equipo> getPostulantesAceptados() {
		List<Equipo> list = new LinkedList<Equipo>();
		for (Object equipo : listPostulantes.getSelectedValues()) {
			list.add((Equipo)equipo);
		}
		return list;
	}

    // End of variables declaration//GEN-END:variables

}
